<!DOCTYPE html>
<html>
<!--
author:lvlu
date:2018-07
desc:this demo is about blog. PLEASE NOTE:If you have trouble running it ,try any of the other demos or connect with auther.
A ny individuals and organizations and not for commercial use, professiona website for customized web site.
-->
<head lang="en">
    <meta charset="UTF-8">
    <title>皮爷の商城——支付页面</title>
    <link rel="stylesheet" href="../static/css/index.css">
    <link href="../static/css/payment.css" rel="Stylesheet" />
    <link rel="icon" href="../static/images/index/py.ico">
    <script src="../static/js/init.js"></script>
    <style>
        .okPay a{
    		color: #FFFFFF;
    	}
    </style>
</head>

<body>
    <!-- 页面顶部-->
    <header id="header"></header>
    <div id="navlist">
        <ul>
            <li class="navlist_gray_left"></li>
            <li class="navlist_gray">确认订单信息</li>
            <li class="navlist_gray_arro"><canvas id="canvas_gray" width="20" height="38"></canvas>
            </li>
            <li class="navlist_blue">支付订单<b></b></li>
            <li class="navlist_blue_arro"><canvas id="canvas_blue" width="20" height="38"></canvas>
            </li>
            <li class="navlist_gray">支付完成<b></b></li>
            <li class="navlist_gray_right"></li>
        </ul>
    </div>
    <!--订单确认-->
    <form action="pay_success.html" method="post" id="pay_form">
        <div id="container" class="clearfix">
            <!-- 支付订单信息-->
            <div class="pay_info">
                <b>订单金额：<i id="total_amount"></i></b><input type="hidden" name="payment" value="0.01" />
                <span id="order_id"></span> <span id="saller"></span> <input type="hidden" name="orderId" />
            </div>
            <!--支付方式-->
            <div id="pay_type">
                <!-- 支付方式头-->
                <div class="pay_type_title">
                    <b>支付宝支付</b>
                </div>
                <div id="dnBank">
                    <ul>
<!-- {#                        <li><input type="radio" name="bankId" value="BOC-NET-B2C" id="02zg">#}
{#                            <label for="02zg"><img src="../static/images/pay/pay_img1.jpg" alt="" /></label>#}
{#                        </li>#}
{#                        <li><input type="radio" name="bankId" value="ICBC-NET-B2C" id="03gs">#}
{#                            <label for="03gs"><img src="../static/images/pay/pay_img2.jpg" alt="" /></label>#}
{#                        </li>#} -->
                    <li><input type="radio" name="bankId" value="CMBCHINA-NET-B2C" id="04zs" checked>
                        <label for="04zs"><img src="../static/images/myOrder/timg%20.jpg" alt="" /></label>
                    </li>

<!-- {#                        <li><input type="radio" name="bankId" value="CCB-NET-B2C" id="05js">#}
{#                            <label for="05js"><img src="../static/images/pay/pay_img4.jpg" alt="" /></label>#}
{#                        </li>#}
{#                        <li><input type="radio" name="bankId" value="ABC-NET-B2C" id="06ny">#}
{#                            <label for="06ny"><span><img src="../static/images/pay/pay_img5.jpg" alt="" /></span></label>#}
{#                        </li>#}
{##} -->
                    </ul>
                </div>

            </div>
            <!--结算条-->
            <div id="count_bar">
                <span class="pay_leftTime">
<!-- {#                    剩余付款时间：<b>15：00</b>#} -->
                    <!--获取待支付时间并更改订单状态-->
                </span>
                <span class="okPay" id="pay_now"><a href="#">确认支付</a></span>
            </div>

        </div>
    </form>
    <div id='loading' style="width:100%; height:100%;position:fixed; top :0px;background:rgba(0, 0, 0, 0.5);text-align:center ;display:none;">
        <div style="position: relative;top:0;left: 0;right: 0;bottom: 0;margin: 0 auto; width:160px;height:120px; z-index:10;line-height:500px;">
            <img src="../static/images/pay/aa.gif" alt="" style="width:100%;height: 100%;">
        </div>
    </div>
    <footer id="footer"></footer>
    <script src="../static/js/jquery-3.1.1.min.js"></script>
    <script src="../static/js/index.js"></script>
    <script>
    </script>
    <script>
        var canvas = document.getElementById("canvas_gray");
        var cxt = canvas.getContext("2d");
        var gray = cxt.createLinearGradient(10, 0, 10, 38);
        gray.addColorStop(0, '#f5f4f5');
        gray.addColorStop(1, '#e6e6e5');
        cxt.beginPath();
        cxt.fillStyle = gray;
        cxt.moveTo(20, 19);
        cxt.lineTo(0, 38);
        cxt.lineTo(0, 0);
        cxt.fill();
        cxt.closePath();
        var canvas = document.getElementById("canvas_blue");
        var cxt = canvas.getContext("2d");
        var blue = cxt.createLinearGradient(10, 0, 10, 38);
        blue.addColorStop(0, '#997679');
        blue.addColorStop(1, '#997679');
        cxt.beginPath();
        cxt.fillStyle = blue;
        cxt.moveTo(20, 19);
        cxt.lineTo(0, 38);
        cxt.lineTo(0, 0);
        cxt.fill();
        cxt.closePath();
    </script>
    <script>
    </script>
    <script src="../static/js/jquery-3.3.1.js"></script>
    <script src="../static/js/jquery.cookie.js"></script>
    <script>
        function orders() {
                    (function ($) {
                        $.getUrlParam = function (name) {
                            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                            var r = window.location.search.substr(1).match(reg);
                            if (r != null) return r;
                            return null;
                        }
                    })(jQuery);
                    var address_id = $.getUrlParam('address_id')[2]
                    var settlement_type= $.getUrlParam('settlement_type')[2]
                    var buy_count = $.getUrlParam('buy_count')?$.getUrlParam('buy_count')[2]:0
                    var sku_id = $.getUrlParam('sku_id')?$.getUrlParam('sku_id')[2]:0
                    var token=localStorage.getItem("dashop_token")
                    var username =  window.localStorage.getItem('dashop_user')
                    if(buy_count!=0&&sku_id!=0){
                        var data={
                            "address_id":address_id,
                            "settlement_type":settlement_type,
                            "buy_count":buy_count,
                            'sku_id':sku_id
                        }
                    }else {
                        var data={
                            "address_id":address_id,
                            "settlement_type":settlement_type
                        }
                    }

                    if (settlement_type==0){
                        push_ajax(0,data)
                    }else if (settlement_type==1){
                        push_ajax(1,data)
                    }
                    function push_ajax(settlement_type,data){
                        $.ajax({
                        type: 'post',
                        url: baseUrl+'/v1/orders/'+username,
                        contentType:'application/json',
                        beforeSend:function(request){
                        request.setRequestHeader("authorization",token)
                        },
                        data:JSON.stringify(data),
                        datatype: 'json',
                        async: false,
                        success: function (response) {
                            var result = JSON.stringify(response)
                            var results = JSON.parse(result)
                            console.log(results.code)
                            if(results.code == 403){
							alert('用户认证已过期，请重新登录');
							window.localStorage.removeItem('dashop_user');
							window.localStorage.removeItem('dashop_token');
							window.localStorage.removeItem('dashop_count');
							location.href = 'login.html'
						}
				            if(results.code == '200'){
                            console.log(results.data)
                            console.log(results.data.order_id)
                            window.localStorage.setItem('dashop_count', results.data.carts_count);
                            $('.my_cart_count').html(results.data.carts_count)
                            $("#total_amount").html(results.data.total_amount+"元")
                            $("#order_id").html("支付订单:"+results.data.order_id)
                            $("#saller").html("收款方:"+results.data.saller+"&nbsp&nbsp")
                            $(".pay_leftTime").html("总金额(含运费):"+results.data.total_amount)
                            var pay_url = results.data.pay_url
                            $(function(){
                                console.log("测试１")
                                $("#pay_now").click(function () {
                                    console.log("测试2")
                                    window.location = pay_url
                })
        })
				}else{
				alert(results.errmsg)
				window.location.href = 'orderConfirm.html'
				}
                    }
                }
            )
                    }
}



window.onload = function () {
    orders()
}
    </script>
</body>

</html>
